package cn.dzz.dao;

import cn.dzz.entity.User;
import cn.dzz.util.HikariUtil;
import cn.dzz.util.JdbcForTxUtil;
import cn.dzz.util.JdbcUtil;
import cn.dzz.util.TransactionManager;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * @author ArkD42
 * @file OA
 * @create 2020 - 06 - 17 - 23:22
 */
public class UserDaoImpl implements UserDao{

    @Override
    public int updateUserById(User user) throws SQLException {
        String sql = new StringBuffer("UPDATE user SET ").
                append("u_name = ?, u_password = ?, u_email = ?, u_phone = ?, u_status = ? ").
                append("WHERE u_id = ?").
                toString();

        return new QueryRunner().update(
                TransactionManager.getCurrentThreadConnection(),
                sql,
                user.getU_name(),
                user.getU_password(),
                user.getU_email(),
                user.getU_phone(),
                user.getU_status(),
                user.getU_id()
        );
    }

/*    String sql = new StringBuffer("UPDATE user SET ").
            append("u_name = ?, u_password = ?, u_email = ?, u_phone = ?, u_status = ? ").
            append("WHERE u_id = ?").
            toString();

        return JdbcForTxUtil.update(
                HikariUtil.getConnection(),
    sql,
            new Object[]{
        user.getU_name(),
                user.getU_password(),
                user.getU_email(),
                user.getU_phone(),
                user.getU_status(),
                user.getU_id()
    }
        );*/
}
